//= require moment
//= require moment/zh-cn.js

//= require bootstrap-datepicker/core
//= require bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.js
//= require bootstrap-datetimepicker

$(function() {
  $('input.datetime_picker').datetimepicker({
    format: 'YYYY-MM-DD HH:mm',
    stepping: '15'
  });

  $('input.date_picker').datepicker({
    orientation: "auto",
    autoclose: true,
    format: "yyyy-mm-dd"
  });  

  $('.date_range_picker').each(function(){
    var $this = $(this)
    var range1 = $($this.find('input')[0])
    var range2 = $($this.find('input')[1])

    if($.trim(range1.val()))
      range2.datepicker("setStartDate", new Date(range1.val()))

    if($.trim(range2.val()))
      range1.datepicker("setEndDate", new Date(range2.val()))

    range1.on("changeDate",function (e) {
      if(e.date)
        range2.datepicker("setStartDate", e.date)
      else
        range2.datepicker("setStartDate", false)
    });

    range2.on("changeDate",function (e) {
      if(e.date)
        range1.datepicker("setEndDate", e.date)
      else
        range1.datepicker("setEndDate", false)
    });
  })
})
